package views;

import java.awt.BorderLayout;
import views.panels.PanelGeneral;
import javax.swing.DefaultComboBoxModel;
import logicBusiness.AreaBL;
import java.util.List;
import logicBusiness.AsignaturaBL;
import models.Asignatura;
import models.Area;

/**
 *
 * @author viviana
 */
public class InterfazConsultarAsignatura extends javax.swing.JFrame {

    private AreaBL areaBo = new AreaBL();
    private AsignaturaBL asignaturaBo = new AsignaturaBL();
    private Asignatura as = new Asignatura();
    private Area ar = new Area();

    /** Creates new form InterfazConsultarAsignatura */
    public InterfazConsultarAsignatura() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        cargarListaGrados();
        cargarListaAreas();
        cargarListaAsignaturas();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        CBGrados = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        CBAreas = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        CBAsignaturas = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        CTNombre = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        CTGrado = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        CTArea = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        CTIntensidad = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        CTProfesor = new javax.swing.JTextField();
        BAceptar = new javax.swing.JButton();

        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 240));
        jLabel1.setText("BUSCAR ASIGNATURA");

        jLabel3.setText("Grado:");

        CBGrados.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBGrados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBGradosActionPerformed(evt);
            }
        });

        jLabel4.setText("Area:");

        CBAreas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBAreas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBAreasActionPerformed(evt);
            }
        });

        jLabel5.setText("Nombre de la Asignatura");

        CBAsignaturas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CBAsignaturas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBAsignaturasActionPerformed(evt);
            }
        });

        jLabel8.setText("Nombre:");

        CTNombre.setEditable(false);

        jLabel9.setText("Grado:");

        CTGrado.setEditable(false);

        jLabel10.setText("Area:");

        CTArea.setEditable(false);

        jLabel11.setText("Intensidad Horaria:");

        CTIntensidad.setEditable(false);

        jLabel12.setText("Profesor que la dicta:");

        CTProfesor.setEditable(false);

        BAceptar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BAceptar.setText("Aceptar");
        BAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5)
                                .addComponent(jLabel3))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(CBAsignaturas, 0, 570, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(CBGrados, 0, 266, Short.MAX_VALUE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel4)
                                    .addGap(18, 18, 18)
                                    .addComponent(CBAreas, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel12)
                                .addComponent(jLabel8)
                                .addComponent(jLabel11))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(CTIntensidad)
                                        .addComponent(CTNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel10)
                                        .addComponent(jLabel9))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(CTArea, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
                                        .addComponent(CTGrado, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)))
                                .addComponent(CTProfesor, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE))
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addGap(260, 260, 260)
                            .addComponent(BAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap()))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(287, 287, 287))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(CBGrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CBAreas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(CBAsignaturas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CTNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CTGrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CTArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CTIntensidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(CTProfesor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addComponent(BAceptar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BAceptarActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_BAceptarActionPerformed

    private void CBAreasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBAreasActionPerformed
        cargarListaAsignaturas();
        CTNombre.setText("");
        CTGrado.setText("");
        CTIntensidad.setText("");
        CTArea.setText("");
        CTProfesor.setText("");
    }//GEN-LAST:event_CBAreasActionPerformed

    private void CBAsignaturasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBAsignaturasActionPerformed
        as = asignaturaBo.consultarAsignatura((CBAsignaturas.getSelectedItem() + ""), CBGrados.getSelectedIndex() - 1);
        ar = areaBo.consultarArea(CBAreas.getSelectedItem() + "");
        if (as != null && ar != null) {
//            CTNombre.setText(as.getNombreAsignatura());
//            CTGrado.setText(as.getIdGrado() + "");
//            CTIntensidad.setText(as.getIntensidadHoraria() + "");
//            CTArea.setText(ar.getNombreArea());
//            CTProfesor.setText(as.getIdProfesor() + "Falta mejorar profesor,.. aun no se como funca");
        }
    }//GEN-LAST:event_CBAsignaturasActionPerformed

    private void CBGradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBGradosActionPerformed
        cargarListaAsignaturas();
        CTNombre.setText("");
        CTGrado.setText("");
        CTIntensidad.setText("");
        CTArea.setText("");
        CTProfesor.setText("");

    }//GEN-LAST:event_CBGradosActionPerformed

    private void cargarListaGrados() {
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBGrados.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccione");
        modelo.addElement("0.  Transicion");
        modelo.addElement("1.  Primero");
        modelo.addElement("2.  Segundo");
        modelo.addElement("3.  Tercero");
        modelo.addElement("4.  Cuarto");
        modelo.addElement("5.  Quinto");
        modelo.addElement("6.  Sexto");
        modelo.addElement("7.  Séptimo");
        modelo.addElement("8.  Octavo");
        modelo.addElement("9.  Noveno");
        modelo.addElement("10. Decimo");
        modelo.addElement("11. Once");
    }

    private void cargarListaAreas() {
        List l = areaBo.consultarAreas();
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBAreas.getModel();
        modelo.removeAllElements();
        for (int i = 0; i < l.size(); i++) {
            modelo.addElement(l.get(i));
        }
        CBAreas.setModel(modelo);
    }

    private void cargarListaAsignaturas() {
        List a = asignaturaBo.consultarAsignaturasAreaGrado(CBAreas.getSelectedItem() + "", CBGrados.getSelectedIndex() - 1);

        DefaultComboBoxModel modelo = (DefaultComboBoxModel) CBAsignaturas.getModel();
        modelo.removeAllElements();
        for (int i = 0; i < a.size(); i++) {
            modelo.addElement(a.get(i));

        }
        CBAsignaturas.setModel(modelo);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazConsultarAsignatura().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BAceptar;
    private javax.swing.JComboBox CBAreas;
    private javax.swing.JComboBox CBAsignaturas;
    private javax.swing.JComboBox CBGrados;
    private javax.swing.JTextField CTArea;
    private javax.swing.JTextField CTGrado;
    private javax.swing.JTextField CTIntensidad;
    private javax.swing.JTextField CTNombre;
    private javax.swing.JTextField CTProfesor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    // End of variables declaration//GEN-END:variables
}
